<?php

class IndexController extends Zend_Controller_Action
{
	private $_auth;
	private $_acl;
    public function init(){
        $acl                = new My_Acl();
        $auth               = $acl->hasIdentity($this->_request);
        $this->_auth        = $auth->getIdentity();
        $this->view->auth   = $this->_auth;
        $this->_acl         = $acl;
        $this->view->acl    = $this->_acl;
        $listAllow          = $acl->listAllowed($this->_auth); 
        $listMenu           = array();
        foreach($listAllow as $row){
            if($row['moduleName'] == 'admin' && $row['actionName'] == 'index' && !in_array($row['controllerName'], $listMenu)){
                $listMenu[]     = $row['controllerName'];
            }
        }
        $this->view->role=$listMenu;
    }
    public function indexAction(){
        $modelRole = new Default_Model_Role();
        $roleCheck = $modelRole->getDataByUserId($this->_auth['userId']);
        $partnerList = array();
        foreach($roleCheck as $row){
            if(!$row['partnerId']){
                continue;
            }
            $partnerId = json_decode($row['partnerId']);      
            if(is_array($partnerId)){
                $partnerList = array_merge($partnerList,$partnerId);
                $partnerList = array_unique($partnerList);
            }
        }     
        if($partnerList){
            $partnerList = array_unique($partnerList);
            if(count($partnerList) == 1){
                if(!isset($homepage)){
                    $homepage = '/default/partner/index';
                }
                $this->_redirect($homepage.'/partnerId/'.$partnerList[0]);
                return;
            }
            $partnerList = '("'.implode('","',$partnerList).'")';
            $modelGame = new Default_Model_Partner();
            $partnerList = $modelGame->getDataByPartnerList($partnerList);
            if(isset($partnerList))
            {
                $this->view->partnerList = $partnerList->toArray();
            }
        }
        
    }//end function
}//end class